﻿using DataModel.Send.Frame;
using DataModel.Receive.Frame;
using DataModel.PublicModel.Typedef;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.IO;

namespace testControl
{
    class Program
    {
        static void Main(string[] args)
        {
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                TextWriter tw = new StreamWriter(ms);
                RequestHisdata objo = new RequestHisdata() { User="Hntj", Message="", Code= ErrorType.OK };
                objo.Data.Fromtime = DateTime.Now.ToString();
                objo.Data.Totime = DateTime.Now.ToString();
                objo.Data.Request = "hisdata";
                objo.Data.Meters.Add("aa");
                objo.Data.Meters.Add("bb");
                objo.Data.Meters.Add("cc");
                //RequestNon objo = new RequestNon() { User = "Hntj", Message = "", Stage = "", Code = DataModel.PublicModel.Typedef.ErrorType.OK };
                Newtonsoft.Json.JsonSerializer.CreateDefault().Serialize(tw, objo);
                tw.Flush();
                ms.Position = 0;
                Console.WriteLine(ms.CanRead);
                Console.WriteLine(ms.CanWrite);
                TextReader tr = new StreamReader(ms);
                string temp = tr.ReadToEnd();
                //temp = "{\"data\":{\"request\":\"non\"},\"user\":\"Hntj\",\"stage\":\"\",\"message\":\"接收数据完成\",\"code\":0}";
                Console.WriteLine(temp);
                temp = PublicLib.Lib.Security.AesSecurity.Encrypt(temp, "Hntj" + (int)(DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 1)).TotalDays);
                Console.WriteLine(temp);
                temp = PublicLib.Lib.Security.AesSecurity.Decrypt(temp, "Hntj" + (int)(DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 1)).TotalDays);
                Console.WriteLine(temp);
                ms.Position = 0;
                var obj = Newtonsoft.Json.JsonSerializer.CreateDefault().Deserialize(tr, objo.GetType());
                var ps = objo.GetType().GetProperties();
                foreach (var prop in ps)
                {
                    Console.WriteLine(prop.Name + ":" + prop.GetValue(obj, null));
                }
            }
            Console.ReadKey();
        }

    }
}
